//
// DepRepoVersion
//
// Copyright (C) jextra.net.
//
//  This file is part of the net.jextra.dep Library.
//
//  The net.jextra.dep Library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  The net.jextra.dep Library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with the net.jextra.dep Library; if not, write to the Free
//  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
//  02111-1307 USA.
//

package net.jextra.dep.repo;

public class DepRepoVersion
{
    // ============================================================
    // Fields
    // ============================================================

    private DepRepo repo;
    private String componentName;
    private String versionNumber;

    // ============================================================
    // Constructors
    // ============================================================

    public DepRepoVersion( DepRepo repo, String componentName, String versionNumber )
    {
        assert repo != null : "repo can not be null";
        assert componentName != null : "componentName can not be null in repo [" + repo + "]";
        assert versionNumber != null : "versionNumber can not be null";

        this.repo = repo;
        this.componentName = componentName;
        this.versionNumber = versionNumber;
    }

    // ============================================================
    // Methods
    // ============================================================

    // ----------
    // public
    // ----------

    public DepRepo getRepo()
    {
        return repo;
    }

    public void setRepo( DepRepo repo )
    {
        this.repo = repo;
    }

    public String getComponentName()
    {
        return componentName;
    }

    public void setComponentName( String componentPath )
    {
        componentName = componentPath;
    }

    public String getVersionNumber()
    {
        return versionNumber;
    }

    public void setVersionNumber( String versionNumber )
    {
        this.versionNumber = versionNumber;
    }

    @Override
    public boolean equals( Object obj )
    {
        if ( !( obj instanceof DepRepoVersion ) )
        {
            return false;
        }

        DepRepoVersion other = (DepRepoVersion) obj;

        if ( !componentName.equals( other.componentName ) )
        {
            return false;
        }
        else if ( !versionNumber.equals( other.versionNumber ) )
        {
            return false;
        }

        return true;
    }
    
    @Override
    public String toString()
    {
        return String.format( "{name=%s,version=%s}", getComponentName(), getVersionNumber() );
    }
}
